<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:comps="http://java.sun.com/jsf/composite/components">
	
<p:panel id="perfilPainel">
	
	<f:facet name="header">
		<h:outputText value="#{locale['adminUsuario.perfil.panelTitulo']}" />
	</f:facet>
		
	<h:form id="perfilForm">
		
		<h:panelGroup layout="block" styleClass="PerfilMessages">
			<p:messages id="cadastroMessages" closable="true" />
		</h:panelGroup>
					
		<h:panelGrid columns="2" columnClasses="gridFormularioEsquerda, gridFormularioDireita">
		
			<h:outputText id="senhaPerfilLbl" value="#{locale['usuario.label.senha']}"
				style="font-weight: bold;" />
			<p:commandButton id="alterarSenhaBtn"
				icon="ui-icon-key"
				value="#{locale['alterarSenha.titulo']}"
				action="#{UsuarioPerfilBean.prepararAlterarSenha()}"
				immediate="true" />
		
			<p:outputLabel id="nomePerfilLbl" for="nomePerfil"
				value="#{locale['usuario.label.nome']}" />
			<p:inputText id="nomePerfil"
				style="width: 450px;"
				required="true"
				styleClass="cadastroInputs"
				label="#{locale['cadastro.label.nome']}"
				value="#{UsuarioPerfilBean.usuario.nome}"
				maxlength="100">
				<f:validator validatorId="validator.MinimoPalavrasValidator" />
				<f:attribute name="minimoPalavras" value="2" />
			</p:inputText>
							
			<p:outputLabel id="emailPerfilLbl" for="emailPerfil"
				value="#{locale['usuario.label.email']}" />
			<p:inputText id="emailPerfil"
				readonly="true"
				disabled="true"
				style="width: 450px;"
				required="true"
				styleClass="cadastroInputs"
				label="#{locale['cadastro.label.email']}"
				value="#{UsuarioPerfilBean.usuario.email}"
				maxlength="100">
				<f:validator validatorId="validator.EmailValidator" />
			</p:inputText>
							
			<p:outputLabel id="localPerfilLbl" for="localPerfil"
				value="#{locale['usuario.label.local']}" />
			<p:inputText id="localPerfil"
				style="width: 450px;"
				required="true"
				styleClass="cadastroInputs"
				label="#{locale['cadastro.label.local']}"
				value="#{UsuarioPerfilBean.usuario.local}"
				maxlength="100">
			</p:inputText>	
				
			<h:outputText id="avatarPerfilLbl" value="#{locale['usuario.label.avatar']}"
				style="font-weight: bold;" />
			<p:commandLink id="avatarPerfil" 
				immediate="true"
				action="#{UsuarioPerfilBean.prepararAlteracaoAvatar()}">
				<h:graphicImage id="avatarUsuario"
					value="resources/images/usuarios/#{UsuarioPerfilBean.usuario.avatar}" 
					width="100" height="100" />				
			</p:commandLink>
					
			<p:outputLabel for="sexoPerfil" value="#{locale['cadastro.label.sexo']}" />
			<p:selectOneRadio id="sexoPerfil"
				required="true"
				styleClass="cadastroInputs"
				value="#{UsuarioPerfilBean.usuario.sexo}">
				<f:selectItems value="#{PaginaInicialBean.sexoList}" />
			</p:selectOneRadio>
					
			<p:outputLabel id="dataNascimentoPerfilLbl" for="dataNascimentoPerfil"
				value="#{locale['cadastro.label.dataNascimento']}" />
			<p:calendar id="dataNascimentoPerfil"
				required="true"
				pattern="dd/MM/yyyy"
				locale="pt_BR"
				mindate="01/01/1900" maxdate="31/12/1994"
				yearRange="c-100:c+100"
				navigator="true"
				value="#{UsuarioPerfilBean.usuario.dataNascimento}" showOn="button" />
					
			<p:outputLabel id="dataCadastroPerfilLbl" for="dataCadastroPerfil"
				value="#{locale['usuario.label.dataCadastro']}" />
			<p:inputText id="dataCadastroPerfil"
				readonly="true"
				disabled="true"				
				value="#{UsuarioPerfilBean.usuario.dataCadastro}">
				<f:convertDateTime pattern="dd/MM/yyyy" />
			</p:inputText>
				
			<p:outputLabel id="biografiaPerfilLbl" for="biografiaPerfil"
				value="#{locale['usuario.label.biografia']}" />
			<p:inputTextarea id="biografiaPerfil"
				value="#{UsuarioPerfilBean.usuario.biografia}" rows="6" cols="60"
				style="width: 450px;"
				counter="contadorBiografiaPerfil"
				counterTemplate="#{locale['crud.mensagens.caracteresRestantes']}"
				maxlength="255">
			</p:inputTextarea>
				
			<p:spacer />
			<h:panelGroup layout="block" 
				style="text-align: right; margin-bottom: 5px; font-size: 0.8em;">
				<h:outputText id="contadorBiografiaPerfil" />
			</h:panelGroup>						
					
		</h:panelGrid>
					
		<h:panelGroup layout="block" style="text-align: right; margin-top: 10px;">
				
			<p:commandButton id="cadastrarBtn"
				styleClass="ui-priority-primary"
				update="perfilForm"
				value="#{locale['cadastro.botao.atualizar']}"
				action="#{UsuarioPerfilBean.salvarAlteracoes()}" />
			
		</h:panelGroup>
				
	</h:form>	
					
</p:panel>
	
<p:dialog id="editarAvatarDialog"
	widgetVar="editarAvatarDlg">
		
		<f:facet name="header">
			<h:outputText value="Alterar Avatar" />
		</f:facet>
	
		<h:form enctype="multipart/form-data">  
		  
		    <p:fileUpload fileUploadListener="#{FileUploaderController.handleFileUpload}"
		    	label="Selecionar"
		    	cancelLabel="Cancelar"
		    	uploadLabel="Enviar"
	            mode="advanced"   
	            update="messages"  
	            sizeLimit="1000000"
	            allowTypes="/(\.|\/)(gif|jpe?g|png)$/">  
			<f:attribute name="subDiretorio" value="usuarios" />
			<f:attribute name="objetoCodigo" value="#{SessaoBean.usuarioAutenticado.codigo}" />
		</p:fileUpload>
		
		<h:panelGroup layout="block" style="text-align: center; margin-top: 10px;">
			
			<p:commandButton value="alterar avatar" 
				update="@all"
				action="#{UsuarioPerfilBean.salvarNovoAvatar()}" />
			
		</h:panelGroup>
		
	    <p:growl id="messages" showDetail="true" />  
		  
	</h:form> 	
	
</p:dialog>

<p:dialog id="alterarSenhaDialogo" widgetVar="alterarSenhaDlg"
	showEffect="slide" hideEffect="slide"
	draggable="false" resizable="false" closable="false"
	modal="true" appendToBody="true">  

    <f:facet name="header">
    	<h:outputText value="#{locale['alterarSenha.titulo']}" />
    </f:facet>
    
	<h:form id="alterarSenhaForm">
		
		<p:messages id="alterarSenhaMsgs" closable="true" />
		<p:spacer height="5" />
		
		<h:panelGrid columns="2">
		
			<p:outputLabel for="senhaAtual" value="#{locale['alterarSenha.label.senhaAtual']}" />
			<p:password id="senhaAtual" required="true" 
				tabindex="1"
				size="40"
				value="#{UsuarioPerfilBean.senhaAtual}">
			</p:password>
			
			<p:outputLabel for="senhaNova1" value="#{locale['alterarSenha.label.senhaNova']}" />
			<p:password id="senhaNova1" required="true" 
				tabindex="2"
				styleClass="inputSenha"
				match="senhaNova2" 
				validatorMessage="#{locale['alterarSenha.msg.naoCorrespondem']}"
				feedback="true"
				inline="true"
				size="40"
				promptLabel="#{locale['alterarSenha.senhaNova.prompt']}"
				weakLabel="#{locale['alterarSenha.forcaSenha.fraca']}"
				goodLabel="#{locale['alterarSenha.forcaSenha.boa']}"
				strongLabel="#{locale['alterarSenha.forcaSenha.forte']}"
				value="#{UsuarioPerfilBean.senhaNova}">
				<f:validateLength minimum="8" />
			</p:password>
			
			<p:outputLabel for="senhaNova2" value="#{locale['alterarSenha.label.senhaNova']}" styleClass="customLabel" />
			<p:password id="senhaNova2" required="true" 
				tabindex="3" 
				styleClass="inputSenha"
				feedback="true"
				inline="true"
				size="40"
				promptLabel="#{locale['alterarSenha.senhaNovaRepetir.prompt']}"
				weakLabel="#{locale['alterarSenha.forcaSenha.fraca']}"
				goodLabel="#{locale['alterarSenha.forcaSenha.boa']}"
				strongLabel="#{locale['alterarSenha.forcaSenha.forte']}"
				value="#{UsuarioPerfilBean.senhaNova}">
				<f:validateLength minimum="8" />
			</p:password>				
		
		</h:panelGrid>
		
		<h:panelGroup layout="block" style="margin-top: 10px; margin-bottom: 10px;">
			
			<p:commandButton value="#{locale['alterarSenha.titulo']}"
				styleClass="left"
				update="alterarSenhaForm"
				tabindex="4"
				action="#{UsuarioPerfilBean.alterarSenha()}" />
			
			<p:commandButton value="#{locale['crud.botao.fechar']}"
			 	styleClass="right"
				tabindex="5"
				immediate="true"
				action="#{UsuarioPerfilBean.alterarSenhaCancelar()}" />

		</h:panelGroup>
		
	</h:form>
	
</p:dialog> 

		
</ui:composition>